package com.iplant.pdm.controller.fpc.partpoint;

import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.pdm.service.FPCService;
import com.iplant.pdm.service.basicenum.fpc.FPCParamType;
import com.iplant.pdm.service.po.bop.partpoint.FPCRoutePartPointParameter;
import com.iplant.pdm.service.po.fpc.FPCProductParameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 工艺工序-工艺参数控制器
 *
 * @author YouWang·Peng
 * 2023-10-12 10:20:01
 */
@RestController
@RequestMapping("/api/FPCRoutePartPointParameter")
public class FPCRoutePartPointParameterController extends BasicController<FPCRoutePartPointParameter> {
    private static final Logger logger = LoggerFactory.getLogger(FPCRoutePartPointParameterController.class);

    public FPCRoutePartPointParameterController() {
        super(FPCRoutePartPointParameter.class);
    }

    @Autowired
    FPCService mFPCService;

    /**
     * 查询未添加的参数列表
     */
    @GetMapping("/QueryToAddList")
    public Object QueryToAddList(HttpServletRequest request) {
        Object wResult = new Object();
        try {
            BMSEmployee wLoginUser = GetSession(request);

            // 获取参数
            int wRoutePartPointID = StringUtils.parseInt(request.getParameter("RoutePartPointID"));
            int wParamType = StringUtils.parseInt(request.getParameter("ParamType"));
            int wRoutePartPointParamID = StringUtils.parseInt(request.getParameter("RoutePartPointParamID"));
            FPCParamType wFPCParamType = FPCParamType.getEnumType(wParamType);
            if (wRoutePartPointID <= 0 || wFPCParamType.getValue() <= 0) {
                return GetResult(RetCode.SERVER_CODE_ERR, RetCode.SERVER_RST_ERROR_OUT);
            }

            ServiceResult<List<FPCProductParameter>> wServiceResult = mFPCService.FPC_QueryToAddList(wLoginUser,
                    wRoutePartPointID, wFPCParamType, wRoutePartPointParamID);

            if (StringUtils.isEmpty(wServiceResult.FaultCode)) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, null);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString(), null, null);
        }
        return wResult;
    }
}
